#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <thread>
#include <mutex>

#include "rtpsession.h"
#include "rtpudpv4transmitter.h"
#include "rtpipv4address.h"
#include "rtpsessionparams.h"
#include "rtperrors.h"
#include "rtplibraryversion.h"
#include "rtppacket.h"
#include "rtpsourcedata.h"

#include "YMessageList.h"

using namespace std;
using namespace jrtplib;

#define RTPLIB_IMPORT  //__declspec(dllimport)
#define RTPLIB_EXPORT  //__declspec(dllexport)
#ifdef RTPLIB_COMPILING
#define RTP_API RTPLIB_EXPORT
#else
#define RTP_API RTPLIB_IMPORT
#endif // RTPLIB_COMPILING

#define MAX_RTP_LEN        1360
#define MAX_VIDEO_BUF_SIZE (128*1024)  

class RTP_API RtpTransceiver : public YMessageListInterface
{
public:
	RtpTransceiver(YMessageListInterface* pDecoder);
	~RtpTransceiver();

	int Init();
	int SendRtp(uint8_t* send_data, const size_t len);

	void ProcessMessage();
	void SendMessage(uint8_t* data, const size_t len);

	struct VideoData {
		uint8_t * pData;
		int       len;
	};

	class MyRTPSession : public RTPSession
	{
	public:
		MyRTPSession(YMessageListInterface* pDecoder);
		~MyRTPSession();
	protected:
		YMessageListInterface * m_pDecoder;
		VideoData     m_videoData;
		//FILE* file_recv;
		//int sn;
		void OnValidatedRTPPacket(RTPSourceData *srcdat, RTPPacket *rtppack, bool isonprobation, bool *ispackethandled);
	};

private:
	MyRTPSession* m_pSession;
	YMessageList* m_pMsg;
	std::mutex    m_mutex;
	bool          m_bExit;
};
